/**
 * 
 */
package org.yi.fc.entity;

import com.google.common.base.Preconditions;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

/**
 * @author ilgqh
 * 文章实体
 */
public class FContent extends Model<FContent> {
	private static final long serialVersionUID = -4802325659453281172L;
	public static final FContent dao = new FContent();
	
	public void saveContent(FContent content){
		Preconditions.checkNotNull(content, "保存文章类型时FcontentType实体不允许为空!");
		this.setAttrs(content).save();
	}
	
	/**
	 * 查询文章
	 * @return
	 */
	public Page<FContent> queryContent(int pageNumber, int pageSize, String keyword){
		
		StringBuilder sb = new StringBuilder("from f_content where 1=1 ");
	
		Integer contentType = this.get("content_type");
		if(contentType != null && !"".equals(contentType)){
			sb.append(" and content_type = ").append(contentType);
		}
		
		String contentStatusEN = this.get("content_status_en");
		if(contentType != null && !"".equals(contentType)){
			sb.append(" and content_status_en = '").append(contentStatusEN).append("'");
		}
		
		if(keyword != null && !"".equals(keyword)){
			sb.append(" and (content_title like '%").append(keyword).append("%' ")
			  .append(" or content_author like '%").append(keyword).append("%' ")
			  .append(" or content like '%").append(keyword).append("%' ) ");
		}
		
		sb.append(" order by content_create_time desc");
		
		return paginate(pageNumber, pageSize, "select * ", sb.toString());
	}
	
}
